<template>
	<view class="container">
		<view class="input-container">
			<view class="input-container-title">直播平台</view>
			<view class="input-item">
				<input type="text" class="content" placeholder="请输入账号" v-model="userAccount" />
			</view>
			<view class="input-item">
				<input :type="passType" class="content" placeholder="请输入密码" v-model="userPass" />
				<image :src="eyeIcon" @tap="isOpen = !isOpen"></image>
			</view>
			<view class="tip">本系统为内部使用，请登陆后体验完整功能</view>
			<view class="input-item"><button type="primary" class="content" @tap="login">登录</button></view>
		</view>
	</view>
</template>

<script>
import { mapActions } from 'vuex';
import routeHanlder from '@/util/routeUtil.js';
export default {
	data() {
		return {
			userAccount: '',
			userPass: '',
			returnUrl: '',
			passType: 'password',
			eyeIcon: '../../static/icon/close-eye.png',
			isOpen: false
		};
	},
	watch:{
		isOpen(e){
			if(e){
				this.passType = 'text'
				this.eyeIcon = '../../static/icon/open-eye.png'
			}else{
				this.passType = 'password'
				this.eyeIcon = '../../static/icon/close-eye.png'
			}
		}
		},
	onLoad(e) {
		if (e.returnUrl) this.returnUrl = e.returnUrl;
	},
	methods: {
		...mapActions('user', ['loginAction']),
		async login() {
			if (!this.userAccount) {
				uni.showToast({
					icon: 'none',
					title: '请输入您的账号'
				})
				return
			}
			if (!this.userPass) {
				uni.showToast({
					icon: 'none',
					title: '请输入您的密码'
				})
				return
			}
			await this.loginAction({ appid:this.$store.state.common.appid, UserAccount:this.userAccount, UserPassword:this.userPass }).then(res => {
				if (res.success) {
					//需要修改密码
					if(res.needToChangepassowrd){
						uni.navigateTo({
							url: `../login/modifyPassword` 
						})
					}else{
						routeHanlder.returnUrlHandler(this.returnUrl || 'pages/index/index');
					}
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

.input-container {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	width: 100%;
	margin-top: 100rpx;
	.input-container-title {
		font-size: 50rpx;
		margin-bottom: 100rpx;
	}
	.input-item {
		width: 75%;
		margin: 0 auto;
		display: flex;
		height: 80rpx;
		line-height: 80rpx;
		align-items: center;
		font-size: 35rpx;
		padding: 20rpx 0;
		border-bottom: 1px solid $uni-color-divider;
		.content {
			flex-grow: 1;
			flex-shrink: 1;
			margin: 20rpx 0;
		}
		image{
			width: 60rpx;
			height: 60rpx;
		}
	}
	.tip{
		display: flex;
		justify-content: center;
		height: 60rpx;
		font-size:30rpx;
		color: rgba(0,0,0,.6);
	}
}
</style>
